﻿<common:LayoutAwarePage
    x:Name="pageRoot"
    x:Class="Microsoft.PlayerFramework.Xaml.DashDemo.SplitPage"
    DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Microsoft.PlayerFramework.Xaml.DashDemo"
    xmlns:data="using:Microsoft.PlayerFramework.Xaml.DashDemo.Data"
    xmlns:common="using:Microsoft.PlayerFramework.Xaml.DashDemo.Common"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:mmppf="using:Microsoft.PlayerFramework"
    mc:Ignorable="d">

    <Page.Resources>
        <local:ResolutionConverter x:Key="resConverter"/>
        <local:BitrateConverter x:Key="rateConverter"/>
        <local:AudioStreamAttributesConverter x:Key="AudioStreamAttributes"/>
        <local:VideoTrackAttributesConverter x:Key="VideoTrackAttributes"/>
    </Page.Resources>

    <!--
        This grid acts as a root panel for the page that defines two rows:
        * Row 0 contains the back button and page title
        * Row 1 contains the rest of the page layout
    -->
    <Grid Style="{StaticResource LayoutRootStyle}">

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!-- Back button and page title -->
        <Grid x:Name="titlePanel">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <Grid>
                <Grid.Background>
                    <LinearGradientBrush EndPoint="1,0">
                        <GradientStop Color="#FF1D1D1D" Offset="0.5"/>
                        <GradientStop Color="White" Offset="1"/>
                    </LinearGradientBrush>
                </Grid.Background>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Button
                x:Name="backButton"
                Click="GoBack"
                IsEnabled="{Binding DefaultViewModel.CanGoBack, ElementName=pageRoot}"
                Style="{StaticResource BackButtonStyle}"/>
                <TextBlock x:Name="pageTitle" Grid.Column="1" Text="{StaticResource AppName}" Style="{StaticResource PageHeaderTextStyle}"/>
            </Grid>
            <Image Source="/Assets/azuremedialogo.png" Grid.Column="1" Stretch="None" VerticalAlignment="Top"/>
        </Grid>

        <Grid x:Name="LayoutRoot" Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>

            <Grid Grid.RowSpan="2" x:Name="LeftPanel">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>

                <!--Video tracks-->
                <StackPanel>
                    <TextBlock Text="Video Tracks" Margin="0,5,0,0" FontSize="13" FontWeight="Bold" Foreground="#eeffffff" HorizontalAlignment="Center"/>
                    <ListBox BorderThickness="0" Width="160" Margin="2" x:Name="videoTracks" ScrollViewer.HorizontalScrollBarVisibility="Hidden" IsEnabled="False">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <Grid>
                                    <ProgressBar Height="18" Width="140" Value="{Binding Bitrate}" Maximum="5000000"/>
                                    <TextBlock Text="{Binding Bitrate, Converter={StaticResource rateConverter}}" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="13" Foreground="#ccffffff"/>
                                </Grid>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
                    <Grid DataContext="{Binding SelectedItem, ElementName=videoTracks, Converter={StaticResource VideoTrackAttributes}}">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <TextBlock Margin="5,0,0,0" Grid.Row="0" Text="Bitrate: " Foreground="#ccffffff"/>
                        <TextBlock Margin="5,0,0,0" Grid.Row="0" Grid.Column="1" Text="{Binding Bitrate, Converter={StaticResource rateConverter}}" Foreground="#ccffffff"/>
                        <TextBlock Margin="5,0,0,0" Grid.Row="1" Text="FourCC: " Foreground="#ccffffff"/>
                        <TextBlock Margin="5,0,0,0" Grid.Row="1" Grid.Column="1" Text="{Binding FourCC}" Foreground="#ccffffff"/>
                        <TextBlock Margin="5,0,0,0" Grid.Row="2" Text="Width: " Foreground="#ccffffff"/>
                        <TextBlock Margin="5,0,0,0" Grid.Row="2" Grid.Column="1" Text="{Binding MaxWidth}" Foreground="#ccffffff"/>
                        <TextBlock Margin="5,0,0,0" Grid.Row="3" Text="Height: " Foreground="#ccffffff"/>
                        <TextBlock Margin="5,0,0,0" Grid.Row="3" Grid.Column="1" Text="{Binding MaxHeight}" Foreground="#ccffffff"/>
                    </Grid>
                </StackPanel>

                <!--Audio stream-->
                <StackPanel Grid.Row="1">
                    <TextBlock Text="Audio Streams" Margin="0,5,0,0" FontSize="13" FontWeight="Bold" Foreground="#eeffffff" HorizontalAlignment="Center"/>
                    <ListBox BorderThickness="0" Width="160" Margin="2" x:Name="audioStreamsList" ScrollViewer.HorizontalScrollBarVisibility="Hidden" IsEnabled="False">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <Grid DataContext="{Binding Converter={StaticResource AudioStreamAttributes}}">
                                    <ProgressBar Height="18" Width="140" Value="{Binding Bitrate}" Maximum="100000"/>
                                    <TextBlock Text="{Binding Bitrate, Converter={StaticResource rateConverter}}" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="13" Foreground="#ccffffff"/>
                                </Grid>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
                    <Grid DataContext="{Binding SelectedItem, ElementName=audioStreamsList, Converter={StaticResource AudioStreamAttributes}}">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <TextBlock Margin="5,0,0,0" Grid.Row="0" Text="Bitrate: " Foreground="#ccffffff"/>
                        <TextBlock Margin="5,0,0,0" Grid.Row="0" Grid.Column="1" Text="{Binding Bitrate, Converter={StaticResource rateConverter}}" Foreground="#ccffffff"/>
                        <TextBlock Margin="5,0,0,0" Grid.Row="1" Text="Sampling Rate: " Foreground="#ccffffff"/>
                        <TextBlock Margin="5,0,0,0" Grid.Row="1" Grid.Column="1" Text="{Binding SamplingRate, Converter={StaticResource rateConverter}}" Foreground="#ccffffff"/>
                        <TextBlock Margin="5,0,0,0" Grid.Row="2" Text="FourCC: " Foreground="#ccffffff"/>
                        <TextBlock Margin="5,0,0,0" Grid.Row="2" Grid.Column="1" Text="{Binding FourCC}" Foreground="#ccffffff"/>
                        <TextBlock Margin="5,0,0,0" Grid.Row="3" Text="Channels: " Foreground="#ccffffff"/>
                        <TextBlock Margin="5,0,0,0" Grid.Row="3" Grid.Column="1" Text="{Binding Channels}" Foreground="#ccffffff"/>
                        <TextBlock Margin="5,0,0,0" Grid.Row="4" Text="Bits/Sample: " Foreground="#ccffffff"/>
                        <TextBlock Margin="5,0,0,0" Grid.Row="4" Grid.Column="1" Text="{Binding BitsPerSample}" Foreground="#ccffffff"/>
                        <TextBlock Margin="5,0,0,0" Grid.Row="5" Text="Packet Size: " Foreground="#ccffffff"/>
                        <TextBlock Margin="5,0,0,0" Grid.Row="5" Grid.Column="1" Text="{Binding PacketSize}" Foreground="#ccffffff"/>
                        <TextBlock Margin="5,0,0,0" Grid.Row="6" Text="Audio Tag: " Foreground="#ccffffff"/>
                        <TextBlock Margin="5,0,0,0" Grid.Row="6" Grid.Column="1" Text="{Binding AudioTag}" Foreground="#ccffffff"/>
                    </Grid>
                </StackPanel>

                <Grid Grid.Row="2">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>
                    <TextBlock Text="Requests" Margin="0,5,0,0" FontSize="13" FontWeight="Bold" Foreground="#eeffffff" HorizontalAlignment="Center"/>
                    <ItemsControl Grid.Row="1" BorderThickness="0" Width="160" Margin="2" x:Name="Requests">
                        <ItemsControl.Template>
                            <ControlTemplate>
                                <ScrollViewer x:Name="ScrollViewer" HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible" Padding="{TemplateBinding Padding}">
                                    <ItemsPresenter />
                                </ScrollViewer>
                            </ControlTemplate>
                        </ItemsControl.Template>
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <TextBlock FontSize="9" Text="{Binding}"/>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                </Grid>
            </Grid>

            <Grid Grid.Column="1">
                <mmppf:MediaPlayer
                    x:Name="player" 
                    Background="Black"
                    IsFullScreenVisible="True"
                    IsResolutionIndicatorVisible="True"
                    IsSignalStrengthVisible="True"/>
                <Border HorizontalAlignment="Stretch" VerticalAlignment="Top" Background="#44ffffff">
                    <Image HorizontalAlignment="Center" Source="/WinAzure_bL_horizontal.png" Stretch="None"/>
                </Border>
            </Grid>

            <Grid Grid.Row="1" Grid.Column="1" x:Name="BottomPanel">
                <TextBox x:Name="TextBoxManifest" BorderThickness="0" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" MaxHeight="150" IsReadOnly="True" Background="Transparent" Foreground="{StaticResource ApplicationForegroundThemeBrush}" AcceptsReturn="True" FontSize="9"/>
            </Grid>
        </Grid>

        <VisualStateManager.VisualStateGroups>

            <!-- Visual states reflect the application's view state -->
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscapeOrWide"/>
                <VisualState x:Name="FullScreenPortrait">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PortraitBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedPageHeaderTextStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="player" Storyboard.TargetProperty="IsFullScreenVisible">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="False"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="player" Storyboard.TargetProperty="IsFullScreen">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="True"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</common:LayoutAwarePage>
